package com.judian.smart.view;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.judian.smart.R;

/**
 * author: Peter
 * date: 2019/08/10 星期六 16:39
 * desc: 弹出对话框
 */
public class DialogAlert extends Dialog implements View.OnClickListener {
    private TextView titleTextView;
    private TextView messageTextView;
    private Button cancleBtn, sureBtn;

    private OnSureListener sureListener;

    public void setSureListener(OnSureListener sureListener) {
        this.sureListener = sureListener;
    }

    public interface OnSureListener {

        void onCancel();

        void onSure();

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.cancle_bt:
                sureListener.onCancel();
                dismiss();
                break;
            case R.id.sure_bt:
                sureListener.onSure();
                dismiss();
                break;

            default:
                break;
        }
    }

    public void init(String title, String message) {
        titleTextView.setText(title);
        messageTextView.setText(message);
    }

    public DialogAlert(Context context) {
        super(context, R.style.MyDialog);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.alert_dialog_verify);
        cancleBtn = findViewById(R.id.cancle_bt);
        sureBtn = findViewById(R.id.sure_bt);
        titleTextView = findViewById(R.id.title_tv);
        messageTextView = findViewById(R.id.message_tv);
        cancleBtn.setOnClickListener(this);
        sureBtn.setOnClickListener(this);
    }
}
